/**
 * Created by user on 17/2/16.
 */
let Joi = require( 'joi');
let KoaRouter = require( 'koa-router');
let userAPIController = require( '../controllers/UserAPIController');

let validator = require('./validator');
let TestModel = require('../models/TestModel');
let Room = require('../models/Room.js');
const router = new KoaRouter();
router.prefix('/api');

router.get(
  '/users/:id',
    validator({
        isAPI: true,
        policy: {
            scope: 'user'
        },
        validate: {
            params: Joi.object({
                id: Joi.number().required()
            })
        }
    }),
  userAPIController.getUser
);

router.get(
  '/user',
    validator({
        isAPI: true,
        policy: {
            scope: 'user'
        }
    }),
  userAPIController.my
);

router.get('/abtest', async function (ctx) {
    ctx.JsonResponse.success(ctx.getRealIp());
});

router.get('/testdb', async function (ctx) {
    TestModel.findOne({ raw: true, where: { uid: '1999840' } });
});

router.get('/room/:id', async function (ctx) {
    let id = ctx.request.params.id;
    Room.findById(id).then(function(room) {
        console.log(room)
    });
});

module.exports = router;
